const mysql = require('mysql')

const connection = mysql.createConnection({
    host: "localhost",
    post: 3306,
    user: "admin",
    password: "root",
    database: "message_board"
})
connection.connect();

function query(sql, data) {
    return new Promise((reslove, reject) => {
        connection.query(sql, data, function (error, result) {
            if (error) {
                reject(error)
            } else {
                reslove(result)
            }
        })
        //关闭连接
        connection.end()
    })
}
module.exports = {
    query
}